import { Injectable } from "@angular/core";
import { Resolve } from '@angular/router';
import { forkJoin, Observable, of } from 'rxjs';
import { first, take } from 'rxjs/internal/operators';
import { Banner, HotTag, Singer, SongSheet } from 'src/app/services/data-types/common.types';
import { HomeService } from 'src/app/services/home.service';
import { MemberService } from "src/app/services/member.service";
import { SingerService } from 'src/app/services/singer.service';
import { StorageService } from "src/app/services/storage.service";
import { User } from "src/app/services/data-types/member.type";
type HomeDataType = [Banner[],HotTag[],SongSheet[],Singer[]]
@Injectable()
export class HomeResolverService implements Resolve<HomeDataType>{
    constructor(
    private homeServer: HomeService,
    private singerServer: SingerService,
    private memberServe: MemberService,
    private storageServe: StorageService
    ){}
    resolve(): Observable<HomeDataType>{
        // const userId = localStorage.getItem("wyUserId");
        // let detail$: Observable<User> | Observable<null> = of(null)
        // if(userId){
        //   detail$ =  this.memberServe.getUserDetail(userId)
        // }
        return forkJoin([
            this.homeServer.getBanners(),
            this.homeServer.getHotTags(),
            this.homeServer.getPerosonalSheetList(),
            this.singerServer.getEnterSinger(),
            // detail$
        ]).pipe(first())
    }
}
